package com.edu.app.service.impl.linkservices;

import com.edu.app.bean.core.SysCustomer;
import com.edu.app.bean.core.SysUser;
import com.edu.app.bean.linkbeans.SysUserCustomer;

import com.edu.app.mapper.linkmappers.SysUserCustomerMapper;
import com.edu.app.service.impl.SysBaseServiceImpl;
import com.edu.app.service.sys.linkservices.SysUserCustomerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserCustomerServiceImpl extends SysBaseServiceImpl<SysUserCustomer,SysUserCustomerMapper> implements SysUserCustomerService {
    @Autowired
    SysUserCustomerMapper sysUserCustomerMapper;

    @Override
    public List<SysCustomer> getCustomerByUserId(Integer id){

        List<SysCustomer> sysCustomerList = sysUserCustomerMapper.getCustomerByUserId(id);
        return sysCustomerList;
    }

    @Override
    public List<SysUser> getUserByCustomerId(Integer id){

        List<SysUser> sysUserList = sysUserCustomerMapper.getUserByCustomerId(id);
        return sysUserList;
    }

    @Override
    public List<SysUser> getUserByCustomerIdWithRole(Integer id, String role_name){

        List<SysUser> sysUserList = sysUserCustomerMapper.getUserByCustomerIdWithRole(id, role_name);
        return sysUserList;
    }

    @Override
    public Integer deleteUserCustomerByCustomerId(Integer customer_id){
        return sysUserCustomerMapper.deleteUserCustomerByCustomerId(customer_id);
    }

    @Override
    public Integer deleteUserCustomerByUserId(Integer user_id){
        return sysUserCustomerMapper.deleteUserCustomerByUserId(user_id);
    }

    @Override
    public PageInfo getUserCustomerByPage(String username, Integer currentPage, Integer pageSize){
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize, true);
        List<SysCustomer> list = sysUserCustomerMapper.getUserCustomerByPage(username);

        PageInfo<SysCustomer> pageInfo = new PageInfo<SysCustomer>(list);
        return pageInfo;
    }

    @Override
    public PageInfo getUserPoCustomerByPage(String username, Integer currentPage, Integer pageSize){
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize, true);
        List<SysCustomer> list = sysUserCustomerMapper.getUserPoCustomerByPage(username);

        PageInfo<SysCustomer> pageInfo = new PageInfo<SysCustomer>(list);
        return pageInfo;
    }

    @Override
    public Integer assignCustomers(String data){
        return sysUserCustomerMapper.assignCustomers(data);
    }
}
